<?php 

$username = $_POST['username'];

$preg='/^[a-z][0-9a-z]{5,8}$/';

$c=preg_match($preg, $username);  //用规则$preg判断$username;

if(!$c){
	$arr=array(
		'error'=>1,
		'info'=>'长度以字母开头的6-8位的数字'
	);
	echo json_encode($arr);
	exit;

}
	
$users=include_once './user.php';

foreach ($users as $user) {
	if($user['username']==$username){
		$arr=array(
			'error'=>1,
			'info'=>'用户名已经存在');
		echo json_encode($arr);
		exit;
	}

}

$arr=array(
	'error'=>0,
	'info'=>'用户名合法',

	);
	echo json_encode($arr);
	exit;





 ?>